package com.itboye.lottery.view.frag_vp_frag;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by  HONGDA on 2018/6/15.
 */
public class PersonalViewpager extends ViewPager {

    //是否可以进行滑动
    private boolean canScroll = true;

    public PersonalViewpager(Context context) {
        super(context);
    }

    public PersonalViewpager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int height = 0;
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            int h = child.getMeasuredHeight();
            if (h > height) height = h;
        }

        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

//    private float xDistance, yDistance, xLast, yLast;
//
//    /* (non-Javadoc)
//     * @see android.widget.AbsListView#onTouchEvent(android.view.MotionEvent)
//     */
//    @Override
//    public boolean onTouchEvent(MotionEvent ev) {
//        switch (ev.getAction()) {
//
//            case MotionEvent.ACTION_DOWN:
//                //获取第一次按下点的坐标
//                xDistance = yDistance = 0f;
//                xLast = ev.getX();
//                yLast = ev.getY();
//                break;
//
//            case MotionEvent.ACTION_MOVE:
////获取移动结束点的坐标　
//                final float curX = ev.getX();
//                final float curY = ev.getY();
////差值
//                xDistance += Math.abs(curX - xLast);
//                yDistance += Math.abs(curY - yLast);
//                xLast = curX;
//                yLast = curY;
//                if (xDistance <= yDistance)
//                    return super.onTouchEvent(ev);  // 消耗
//                else
//                    return false;                   // 往下传递
//
//        }
//        return super.onTouchEvent(ev);
//    }

    public void setCanScroll(boolean canScroll) {
        this.canScroll = canScroll;
    }

//    @Override
//    public boolean onInterceptTouchEvent(MotionEvent ev) {
//        return canScroll;
//    }

//    @Override
//    public boolean onInterceptTouchEvent(MotionEvent arg0)
//    {
//        getParent().requestDisallowInterceptTouchEvent(true);
//        return super.onInterceptTouchEvent(arg0);
//    }
}
